package DAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Model.Cid;
import Model.Convenio;
import Model.Paciente;
import Utils.Conexao;

import com.mysql.jdbc.CallableStatement;
import com.mysql.jdbc.PreparedStatement;

public class CidDAO {

	public static ArrayList<Cid> GetCidArrayList()
	{
		ArrayList<Cid> arrCid = new ArrayList<Cid>(); 
		Connection con  = Conexao.getConection();
		try
		{
			String sqlQuery = "call spc_select_diagnosticos()";
			CallableStatement call = (CallableStatement) con.prepareCall(sqlQuery);			
			ResultSet rs = call.executeQuery();
			
			while(rs.next())
			{
				Cid cid = CidDAO.setInstance(rs);
				arrCid.add(cid);
			}
			con.close();
			call.close();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
		
		return arrCid;
	}	
	
	public static Cid setInstance(ResultSet res) throws SQLException
	{
		Cid cid = new Cid();
		cid.setId(res.getInt("id_cid"));
		cid.setCodigoCid(res.getString("cod_cid"));
		cid.setDescricao(res.getString("descricao"));				
		return cid;		
	}
}
